
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		$("a#look-up").click(function() {
			var cTable = $('#businessTypeTable')
			.dataTable(
					{
						"sDom" : 'rtip',
						"sPaginationType" : "bootstrap",
						"iDisplayLength" : 10,
						"bServerSide" : true,
						"bPaginate" : true,
						"sAjaxSource" : "businessTypeTableAjax.action",
						"bDestroy": true,
						"bRetrieve": true,
						"aoColumnDefs" : [ {
							"fnRender" : function(o, val) {
								return '<input type="radio" name="radioBusiness" class="radioBusiness" value=' + o.aData[0] + '>';
							},		
							"aTargets" : [ 0 ]
						} ]
					});		
			
			
			$('#search-business').click(function(){			
				var name = $("input[name=businessNameLookUp]").val();
				var sicCode = $("input[name=sicCode]").val();	
				if(jQuery.trim(name).length == 0 && jQuery.trim(sicCode).length == 0){
					cTable.fnFilter(name, 1, true, false);
					cTable.fnFilter(name, 2, true, false);
				}
				else{
					if(jQuery.trim(name).length > 0 && jQuery.trim(sicCode).length == 0)
						cTable.fnFilter(name, 1, true, false);
					else if(jQuery.trim(name).length == 0 && jQuery.trim(sicCode).length > 0);
						cTable.fnFilter(sicCode,2, true, false);
				}
				
			});
			
			$('#none-business').click(function(){			
				$("#txtBussinessName").val("");
				$("#txtSICCode").val("");
			});
			
			$('#clear-business').click(function(){				
				$("#txtBussinessName").val("");
				$("#txtSICCode").val("");
				cTable.fnFilter("", 1, true, false);
				cTable.fnFilter("", 2, true, false);
				$("input[name=businessNameLookUp]").val("");
				$("#sicCodeId").val("");
			});
			
		});	
		
		
		$("#btnSelect").click(function(){
			var id = $("input[name=radioBusiness]:checked").val();
			var name = $("input[name=radioBusiness]:checked").parent().next().html();
			var code = $("input[name=radioBusiness]:checked").parent().next().next().html();
			$("#businessIdHidden").val(id);
			$("#txtBussinessName").val(name);
			$("#txtSICCode").val(code);			
			cTable.dataTable().fnDestroy();
		});
	});

	
</script>

<div class="modal hide" id="lookUpBusiness">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">x</button>
		<h3>Business Type</h3>
	</div>
	<div class="modal-body">
		<div id="tblList" class="box-content">
			<form action="#" class='validate form-horizontal' method="post">
				<div class="control-group">
					<div id="search-box">
						<div class="row-fluid force-margin">
							<div class="span3">
								<label for="basic" class="control-label">Business Name:</label>
								<div class="controls">
									<input type="text" name="businessNameLookUp" id=""
										class='input-square'>
								</div>
							</div>
							<div class="span3">
								<label for="basic" class="control-label">SIC Code:</label>
								<div class="controls">
									<input type="text" name="sicCode" id="sicCodeId"
										class='input-square'>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="control-group">
					<div id="button-menu-top" class="button-menu">
						<ul>
							<li><a id="search-business" class="btn btn-success">Search
									Business Type</a></li>
							<li><button id="none-business" data-dismiss="modal"
									class="btn btn-success">None</button></li>
							<li><a id="clear-business" class="btn btn-success">Clear</a></li>

						</ul>
					</div>
				</div>
				<!-- <div class="control-group">
					<div id="inactive">
						<div class="controls">
							<label class="checkbox"><input type="checkbox"
								name="check-inactive" id="check-inactive"> Include
								in-active contact?</label>
						</div>
					</div>
				</div> -->
				<div class="control-group">
					<table id="businessTypeTable"
						class="table table-striped table-bordered">
						<thead>
							<tr>
								<th></th>
								<th>Business Type Name</th>
								<th>SIC Code</th>
														
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
			</form>
		</div>
	</div>
	<div class="modal-footer">
		<a href="#" class="btn" data-dismiss="modal" id="btnClose" >Close</a>
		<a href="#" class="btn btn-primary" data-dismiss="modal"
			id="btnSelect"> Select </a>
	</div>
	
	<!-- Da chuyen sang file create 
	 <input type="hidden" id="" name="idBusiness"> -->
</div>